package demo1;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class DeleteStudent {
    public static void delete(Connection connection , int id) throws SQLException {
        if(id == -1){
            String sql = "delete from student ";
            PreparedStatement statement = connection.prepareStatement(sql);
            if(statement.executeUpdate()>=1){
                System.out.println("全部删除成功");
            }else {
                System.out.println("删除失败");
            }
            return;
        }

        String sql = "delete from student where id=?";
        PreparedStatement statement = connection.prepareStatement(sql);
        statement.setInt(1,id);
        if(statement.executeUpdate()>=1){
            System.out.println("删除成功");
        }else {
            System.out.println("删除失败");
        }
    }
}
